#pragma once
#include <sstream>

#include "basic.hpp"

enum OpcodeFmt
{
  Binary,
  Hex,
};

template<OpcodeFmt fmt>
RET_OPCODE opcode_wrapper(const std::string& opcode)
{
  if constexpr (fmt == OpcodeFmt::Binary) {
    std::stringstream ss;
    for (size_t pos_substr=0; pos_substr<OPCODE_LEN; pos_substr+=SUBSTR_LEN) {
      ss << opcode.substr(pos_substr, SUBSTR_LEN) << ' ';
    }
    return ss.str();
  } else if constexpr (fmt == OpcodeFmt::Hex) {
    std::stringstream ss;
    ss << "0x" ;
    for (size_t pos_substr=0; pos_substr<OPCODE_LEN; pos_substr+=SUBSTR_LEN) {
      unsigned long opcode_digits = std::stoul(opcode.substr(pos_substr, SUBSTR_LEN), 0, 2);
      ss << std::hex << opcode_digits;
    }
    return ss.str();
  }
}
